package com.zhuiyun.project.api.check.mapper;

import com.zhuiyun.project.api.check.entity.Check;
import com.zhuiyun.project.api.check.model.CheckModel;
import com.zhuiyun.project.common.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CheckMapper extends BaseMapper<Check> {

    /**
     * @param toUserId
     * @Author kdj
     * @Description 获取系统列表
     * @Date 2023/8/6 1:47
     * @Return java.util.List<com.zhuiyun.project.api.check.model.CheckModel>
     */
    @Select("select message.uuid,c.is_read,c.create_time,c.check_reason,c.to_user_id from check_audit c left join message on message.id=c.message_id where to_user_id =#{toUserId} and del_flag=0")
    List<CheckModel> getSystemList(int toUserId);

    /**
     * @param uuid
     * @param toUserId
     * @Author kdj
     * @Description 修改未读状态
     * @Date 2023/8/6 1:55
     * @Return int
     */
    @Update("UPDATE check_audit " +
            "SET is_read = 1, update_time = NOW() " +
            "WHERE create_time <= (" +
            "   SELECT ca2.create_time " +
            "   FROM (SELECT * FROM check_audit) ca2 " +
            "   LEFT JOIN message m ON m.id = ca2.message_id " +
            "   WHERE m.uuid = #{uuid}" +
            ") " +
            "AND to_user_id = #{toUserId}")

    int maskDel(String uuid, Integer toUserId);
}
